﻿using System;
using System.Text.RegularExpressions;
using JetBrains.Annotations;

namespace WikiDoc.Lines
{
    /// <summary>
    /// 表示一个缩进行即前导至少一个空白的行
    /// </summary>
    public class IndentLine : WikiLine
    {
        /// <summary>
        /// 初始化 <see cref="IndentLine"/> 类的新实例.
        /// </summary>
        /// <param name="line">The line.</param>
        protected IndentLine(string line) : base(line, LineTypes.Indent)
        {
        }


        /// <summary>
        /// 缩进行定义：前导若干空格加若干字符
        /// </summary>
        public static readonly Regex Pattern = new Regex(
            @"\A (\s+)  (.+)",
            RegexOptions.Compiled |
            RegexOptions.CultureInvariant |
            RegexOptions.Singleline |
            RegexOptions.IgnorePatternWhitespace);

        [CanBeNull]
        public static WikiLine TryParse(string line)
        {
            if (string.IsNullOrEmpty(line)) return null;

            return char.IsWhiteSpace(line[0])
                       ? new IndentLine(line)
                       : null;
        }
    }
}
